package com.ksyun.alert.calculate;

import com.ksyun.alert.biz.bo.immediate.ImmediateCalculateBO;
import com.ksyun.alert.dto.MetricDTO;
import com.ksyun.alert.entity.AlertRulesDO;
import com.ksyun.alert.service.AlertRulesService;
import com.ksyun.alert.service.CalculateImmediateService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

/**
 * 实时计算类
 * @author 蓝
 * @date 2024-05-11
 */
@Component
public class CalculateImmediate {

    @Resource
    private AlertRulesService alertRuleService;
    @Resource
    private CalculateImmediateService calculateImmediateService;

    public void calculateNow(List<MetricDTO> metricsList) {

        // 通过拿到的数据实时计算属于实时计算的指标
        List<AlertRulesDO> immediateRulesList = alertRuleService.getImmediateRules();
        //获取到表达式所需参数
        ImmediateCalculateBO immediateCalculateBO = calculateImmediateService.doResolveNow(metricsList, immediateRulesList);
        //遍历规则列表
        for (AlertRulesDO alertRulesDO : immediateRulesList) {
            calculateImmediateService.doCalculateNow(immediateCalculateBO, alertRulesDO);
        }
    }
}
